from django.db import models


class Country(models.Model):
    created = models.DateTimeField(auto_now_add=True, editable=False)
    updated = models.DateTimeField(auto_now=True, editable=False)

    name = models.CharField('Denumire', max_length=20, unique=True, help_text='Denumirea tarii')

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = 'country'
        verbose_name_plural = 'countries'


class County(models.Model):
    created = models.DateTimeField(auto_now_add=True, editable=False)
    updated = models.DateTimeField(auto_now=True, editable=False)

    name = models.CharField('Denumire', max_length=20, unique=True, help_text='Denumirea judetului')
    country = models.ForeignKey('Country', verbose_name='Tara', help_text='Tara din care face parte judetul')

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = 'judet'
        verbose_name_plural = 'judete'
        unique_together = (('name', 'country'),)


class Address(models.Model):
    created = models.DateTimeField(auto_now_add=True, editable=False)
    updated = models.DateTimeField(auto_now=True, editable=False)

    address = models.TextField('adresa', max_length=100, help_text='Adresa de strada')
    county = models.ForeignKey(County, verbose_name=u'Judet')

    def __unicode__(self):
        return "County: %s, Country: %s, Address: %s" % (
            self.county,
            self.county.country,
            self.address)

    class Meta:
        verbose_name = 'adresa'
        verbose_name_plural = 'adrese'
        unique_together = (('address', 'county'),)


class Partner(models.Model):
    created = models.DateTimeField(auto_now_add=True, editable=False)
    updated = models.DateTimeField(auto_now=True, editable=False)

    name = models.CharField('Denumire', max_length=50, unique=True, help_text='Denumirea partenerului persoana juridica sau fizica')
    address = models.ForeignKey(Address, verbose_name='Adresa')

    fiscal_code = models.DecimalField('CIF', max_digits=10, decimal_places=0, unique=True, help_text='Cod de identificare fiscala (CIF/CUI)')
    fiscal_attr = models.CharField('Atribut fiscal', max_length=2, blank=True, null=True, help_text='Categoria de platitor de taxe si impozite la bugetul de stat')

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = 'partener'
        verbose_name_plural = 'parteneri'
        unique_together = (('name', 'address', 'fiscal_code'),)


class Workplace(models.Model):
    created = models.DateTimeField(auto_now_add=True, editable=False)
    updated = models.DateTimeField(auto_now=True, editable=False)

    name = models.CharField('Denumire', max_length=20, unique=True, help_text='Denumirea punctului de lucru (farmacie)')

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = 'punct de lucru'
        verbose_name_plural = 'puncte de lucru'


class Vat(models.Model):
    created = models.DateTimeField(auto_now_add=True, editable=False)
    updated = models.DateTimeField(auto_now=True, editable=False)

    value = models.DecimalField('Valoare', max_digits=2, decimal_places=0, unique=True, help_text='Valoarea cotei procentuale a taxei pe valoare adaugata')
